<template>
	<view class="nav-box" v-if="isShowNavBar">
		<u-navbar :title="title" @leftClick="navigateBack"></u-navbar>
	</view>
</template>

<script setup>
	import { onMounted } from 'vue'
	
	defineProps({
		/**
		 * 导航栏标题
		 */
		title: {
			type: String,
			default: ''
		},
		/**
		 * 是否显示导航栏
		 */
		isShowNavBar:{
			type:Boolean,
			default:()=>{
				const pages = getCurrentPages()
				return pages.length > 1
			}
		}
	})
	/**
	 * @description: H5 App通用方案 解决H5刷新返回失败问题
	 * @param {*返回前count个页面，默认1} count
	 */
	const navigateBack = (count = 1) => {
		const pages = getCurrentPages()
		if(pages.length === 1){
			if (typeof count === 'number'){
				history.go(-count)
			}
			else{
				history.back()
			}
		}
		else{
			uni.navigateBack()
		}
	}
</script>

<style lang="scss">
	.nav-box {
		padding-top: 44px;
	}
</style>